

#include <sdk_llist.h>
#include <sdk_mem.h>

#include <stdio.h>

int main(){

  printf("Testing linked list (not really) implementation.\n");
  sdk_llist_t *list = SDK_ALLOC_LLIST();

  printf("SDK_WIDTH=%d\n", SDK_WIDTH);
  printf("sizeof(sdk_llist_t) = %d\n", sizeof(sdk_llist_t));
  list->list = 0xFFFF;
  printf("Full list bitmask: 0x%04x\n", list->list);

  printf("Adding elements to the llist...\n");
  list->list = 0;
  sdk_llist_add(list, 1);
  sdk_llist_add(list, 2);
  sdk_llist_add(list, 3);
  sdk_llist_add(list, 4);
  sdk_llist_add(list, 9);
  sdk_llist_add(list, 11);
  sdk_llist_add(list, 12);
  sdk_llist_add(list, 14);
  printf("Partial list bitmask: 0x%04x\n", list->list);

  if (sdk_llist_contains(list, 1)){
    printf("  List contains 1: true\n");
  } else {
    printf("  List contains 1: false\n");
  }
  if (sdk_llist_contains(list, 5)){
    printf("  List contains 5: true\n");
  } else {
    printf("  List contains 5: false\n");
  }
  if (sdk_llist_contains(list, 9)){
    printf("  List contains 9: true\n");
  } else {
    printf("  List contains 9: false\n");
  }
  if (sdk_llist_contains(list, 14)){
    printf("  List contains 14: true\n");
  } else {
    printf("  List contains 14: false\n");
  }
  if (sdk_llist_contains(list, 11)){
    printf("  List contains 11: true\n");
  } else {
    printf("  List contains 11: false\n");
  }
  printf("Printing list:\n");
  sdk_llist_print(list);

  printf("Removing 9...\n");
  sdk_llist_remove(list, 9);
  printf("Checking to see if list still contains 9: ");
  if (sdk_llist_contains(list, 9))
    printf("Error, still contains 9.\n");
  else 
    printf("OK\n");

  printf("Printing list:\n");
  sdk_llist_print(list);

  printf("Now using a new list.\n");
  sdk_llist_t *new_list = sdk_llist_full_list();
  sdk_llist_print(new_list);

  sdk_llist_remove(new_list, 9);
  sdk_llist_remove(new_list, 9);
  sdk_llist_print(new_list);

}
